﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;


namespace Sistema_de_Taller.SDT_UI.Client
{
    public partial class client_view : System.Web.UI.UserControl
    {
        public static UInt32 Client_ID;

        protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem edititem = e.Item as GridEditableItem;
            String ClientID = edititem["Client_ID"].Text;
            String query = string.Format("~/SDT_UI/Client/ClientDetails.aspx?Id={0} ", ClientID);
            Response.Redirect(query);
           /* GridEditableItem edititem = e.Item as GridEditableItem;
            txtName.Text = edititem["Client_Name"].Text;
            txtSocial.Text = edititem["Client_Social"].Text;
            txtState.Text = edititem["Client_State"].Text;
            txtResidence.Text = edititem["Client_Residence"].Text;
            txtMail.Text = edititem["Client_Email"].Text;
            //txtPhone.Text = edititem["Client_Phone"].Text;
            //dpDateUp = edititem["Client_Phone"];
            txtCountry.Text = edititem["Client_Country"].Text;
            txtProvince.Text = edititem["Client_Province"].Text;
            txtCity.Text = edititem["Client_City"].Text;
            txtPostCode.Text = edititem["Client_PostCode"].Text;
            Client_ID = Convert.ToUInt32(edititem["Client_ID"].Text);
            pnlUpdate.Visible = true;*/
            
        }



        protected void dpDateUp_Load(object sender, EventArgs e)
        {
            dpDateUp.SelectedDate = DateTime.Today;
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            //Esto no hace nada, solo refresh. Habria que cambiar el responde.redirect por algo que sea refreshpage, aunque si asi anda dejemoslo
            Response.Redirect("~/SDT_UI/Client/ViewClients.aspx");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            //Aca se corre la query que actualizaria los campos de la fila correspondiente
            Common_Files.Definitions.Client Client = new Common_Files.Definitions.Client();

            Client.Client_Name = txtName.Text;
            Client.Client_Social = txtSocial.Text;
            Client.Client_State = txtState.Text;
            Client.Client_Residence = txtResidence.Text;
            Client.Client_Email = txtMail.Text;
            Client.Client_DateUp = dpDateUp.SelectedDate.Value;
            Client.Client_Country = txtCountry.Text;
            Client.Client_Province = txtProvince.Text;
            Client.Client_City = txtCity.Text;
            Client.Client_PostCode = txtPostCode.Text;
            Client.Client_ID = Client_ID;
            SDT_DAL.Utilities.Client_DAL inserto = new SDT_DAL.Utilities.Client_DAL();
            inserto.ClientUpdate(Client);
            
            
            Response.Redirect("~/SDT_UI/Client/ViewClients.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }






    }

}